home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 626-650 / 641 / tlog / monthtot.tlog < prev    next >
Text File  |  1995-03-15  |  5KB  |  164 lines

  1. /*
  2.  * MonthTot.tlog
  3.  * AREXX report for TLog that prints the total monthly distances and compare
  4.  * the monthly total with the total for SearchKey records.
  5.  */
  6.  
  7. /*
  8.  *  Start at the begining of the data base and keep getting the next record
  9.  *  and add up any distances until you get to the end.  Right now the only
  10.  *  way to tell you're at the end is when nextrec result is lastrec
  11.  *
  12.  *  'Filter out' any record containing the key SearchKey. It's distance is
  13.  *   summed in a different stem variable and printed for comparison.
  14.  */
  15.  
  16. /*
  17.  *  SearchKey is the 1st argument to MonthTot.tlog. If no argument is
  18.  *  specified, then default to GOAL.
  19.  */
  20.  
  21. PARSE UPPER ARG SearchKey
  22.  
  23. IF SearchKey = "" THEN SearchKey = "GOAL"
  24.  
  25. OPTIONS RESULTS
  26. OPTIONS FAILAT 10
  27.  
  28. /* add the necessary libraries */
  29. IF(~EXISTS("libs:rexxsupport.library")|~EXISTS("libs:rexxarplib.library")|~EXISTS("libs:screenshare.library")) THEN
  30.  DO
  31.     SAY "Couldn't find needed library (rexxsupport, rexxarplib, screenshare, or rexxmathlib)."
  32.     EXIT 20
  33.  END
  34.  
  35. IF ~SHOW('L','rexxsupport.library') THEN
  36.    CALL ADDLIB('rexxsupport.library',0,-30)
  37. IF ~SHOW('L','rexxarplib.library') THEN
  38.    CALL ADDLIB('rexxarplib.library',0,-30)
  39. IF ~SHOW('L','rexxmathlib.library') THEN
  40.    CALL ADDLIB('rexxmathlib.library',0,-30)
  41.  
  42.  
  43.  
  44.  
  45.  
  46. /* setup the port to tlog */
  47. ADDRESS 'TLOG'
  48.  
  49.  
  50. /* Open our  window */
  51. CALL open out,"con:0/0/640/170/Monthly Training Totals "|| SearchKey
  52. IF ~RESULT THEN DO
  53.    SAY "Open failure ... sorry"
  54.    EXIT 10
  55. END
  56. CSI = '9B'x
  57.  
  58. /* Initialize the a table of monthly totals */
  59. distance.JAN.total = 0;    distance.JAN.SearchKey = 0;
  60. distance.FEB.total = 0;    distance.FEB.SearchKey = 0;
  61. distance.MAR.total = 0;    distance.MAR.SearchKey = 0;
  62. distance.APR.total = 0;    distance.APR.SearchKey = 0;
  63. distance.MAY.total = 0;    distance.MAY.SearchKey = 0;
  64. distance.JUN.total = 0;    distance.JUN.SearchKey = 0;
  65. distance.JUL.total = 0;    distance.JUL.SearchKey = 0;
  66. distance.AUG.total = 0;    distance.AUG.SearchKey = 0;
  67. distance.SEP.total = 0;    distance.SEP.SearchKey = 0;
  68. distance.OCT.total = 0;    distance.OCT.SearchKey = 0;
  69. distance.NOV.total = 0;    distance.NOV.SearchKey = 0;
  70. distance.DEC.total = 0;    distance.DEC.SearchKey = 0;
  71. distance.YEAR.total = 0;    distance.YEAR.SearchKey = 0;
  72.  
  73.  
  74. /* use TLog dateformat MMM DD YY and grab the 1st 3 chars as the month */
  75. GetDateFormat
  76. oldFormat = RESULT
  77. DateFormat 4
  78.  
  79. /*
  80.  *  IF you have been making entries into the data base, it is best to
  81.  *  flush its buffers by doing a close first.
  82.  */
  83. CloseDB
  84.  
  85. /* Open the data base and mark the END record */
  86. OpenDB
  87. LastRec
  88. lastDataRecord = RESULT
  89.  
  90. /*
  91.  *  Here the distance field, dbdist, is added to the running total for the
  92.  *  month.  The month is found by extracting a substring of the date field,
  93.  *  dbdate. We also filter out (don't add) any distance that comes from a record
  94.  *  with a particular dbkey, SearchKey, and save them in a another stem.
  95.  */
  96.  
  97. /* get the first record and its data */
  98. FirstRec
  99. IF (rc~=0) THEN EXIT rc
  100.  
  101. /* Now loop forever, or until nextrec yields the last record */
  102. DO FOREVER
  103.     /* After the date, the fields in a record are delineated by spaces */
  104.     PARSE VAR RESULT '"' dbdate '"' dbheart dbdist dbtime dbweight dbtemp dbkey
  105.     month = SUBSTR(dbdate,1,3)
  106.     PARSE UPPER VAR dbkey testkey '.'
  107.     /* Is the SearchKey is a substring of the current key? */
  108.     IF  INDEX(testkey,  SearchKey, 1) ~= 0 THEN DO
  109.         distance.month.SearchKey =  distance.month.SearchKey + dbdist
  110.         distance.YEAR.SearchKey =  distance.YEAR.SearchKey + dbdist
  111.     END
  112.     ELSE DO /* save all other distances in the  monthly total */
  113.             distance.month.total =  distance.month.total + dbdist
  114.             distance.YEAR.total =  distance.YEAR.total + dbdist
  115.     END
  116.     IF ( (rc~=0) | ( RESULT = lastDataRecord )) THEN BREAK
  117.     NextRec
  118. END
  119.  
  120. /* restore the date format */
  121. DateFormat oldFormat
  122.  
  123.  
  124. CALL SCREENTOFRONT()
  125.  
  126. /* Now generate your reports printing out our monthly totals */
  127.  
  128. /* tab is column 15x of the current line */
  129. tab = '0D'x CSI'15C'
  130.  
  131. CALL writeln out, "Total distances by month:"
  132. /* put up label in bold color 1 and restore */
  133. CALL writech out, CSI'1;33;40m'
  134. CALL writeln out, "      Actual" tab SearchKey
  135. CALL writech out, CSI'0;31;40m'
  136.  
  137. CALL writeln out, " " JAN distance.JAN.total    tab distance.JAN.SearchKey
  138. CALL writeln out, " " FEB distance.FEB.total    tab distance.FEB.SearchKey
  139. CALL writeln out, " " MAR distance.MAR.total    tab distance.MAR.SearchKey
  140. CALL writeln out, " " APR distance.APR.total    tab distance.APR.SearchKey
  141. CALL writeln out, " " MAY distance.MAY.total    tab distance.MAY.SearchKey
  142. CALL writeln out, " " JUN distance.JUN.total    tab distance.JUN.SearchKey
  143. CALL writeln out, " " JUL distance.JUL.total    tab distance.JUL.SearchKey
  144. CALL writeln out, " " AUG distance.AUG.total    tab distance.AUG.SearchKey
  145. CALL writeln out, " " SEP distance.SEP.total    tab distance.SEP.SearchKey
  146. CALL writeln out, " " OCT distance.OCT.total    tab distance.OCT.SearchKey
  147. CALL writeln out, " " NOV distance.NOV.total    tab distance.NOV.SearchKey
  148. CALL writeln out, " " DEC distance.DEC.total    tab distance.DEC.SearchKey
  149. CALL writeln out,"-------------------------"
  150. CALL writeln out, " TOT" distance.YEAR.total tab   distance.YEAR.SearchKey
  151.  
  152.  
  153. CALL writeln out, " "
  154. /* put up prompt in color 2 */
  155. CALL writech out, CSI'0;32;40m'
  156. CALL writeln out, "Press <Return> to exit"
  157. CALL readln out
  158.  
  159. CALL SCREENTOBACK()
  160.  
  161. EXIT
  162.  
  163.  
  164.